﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ChineseSchool.BLL;
using ChineseSchool.Models.Hethong;

namespace ChineseSchool.UserControl
{
    public partial class LastestNews : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblLastestNews.Text = LoadHotNewsContent();
            }
        }

        public string LoadHotNewsContent()
        {
            string format = "ddd, dd/MM/yyyy h:mm:ss tt";
            string strNews = "";
            List<M_News> lstNews = (new B_News()).GetTop10News(10);
            if (lstNews != null && lstNews.Count > 0)
            {
                strNews += "<ul id=\"scrollerNews\">";
                for (int j = 0; j < lstNews.Count; j++)
                {
                    strNews += "<li><a href=\"" + Util.MakeLinkNewsDetail(lstNews[j].newsID.ToString(), Encode.Uni2KD(lstNews[j].title.ToString())) + "\">";
                    strNews += "<img alt=\"\" src=\"" + lstNews[j].imageUrl.ToString() + "\" width=\"50\" height=\"50\" align=\"left\" /></a>";
                    strNews += "<span>" + lstNews[j].postDate.ToString(format) + "</span> ";
                    strNews += "<a href=\"" + Util.MakeLinkNewsDetail(lstNews[j].newsID.ToString(), Encode.Uni2KD(lstNews[j].title.ToString())) + "\">" + lstNews[j].title.ToString() + "</a></li>";
                    strNews += "<div class=\"clear\"></div>";
                }
                strNews += "</ul>";
            }
            return strNews;
        }
    }
}